package cn.msqweb.controller;

import cn.msqweb.entity.MemberCollection;
import cn.msqweb.entity.Prod;
import cn.msqweb.entity.ProdComm;
import cn.msqweb.model.Result;
import cn.msqweb.service.MemberCollectionService;
import cn.msqweb.util.AuthUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "会员收藏商品接口管理")
@RequestMapping("p/collection")
@RestController
public class MemberCollectionController {
    @Resource
    private MemberCollectionService memberCollectionService;

    //    p/collection/count
    @ApiOperation("会员收藏的商品数量")
    @GetMapping("count")
    public Result<String> loadMemberCollectionCount(){
        long count = memberCollectionService.count(new LambdaQueryWrapper<MemberCollection>()
                .eq(MemberCollection::getOpenId, AuthUtils.getLoginMemberOpenId()));
        return Result.success(String.valueOf(count));
    }

    //    p/collection/prods?current=1&size=10
    @ApiOperation("分页查询会员收藏商品列表")
    @GetMapping("prods")
    public Result<Page<Prod>> loadMemberCollectionProdPage(@ApiParam("页码") @RequestParam Long current,
                                                           @ApiParam("每页显示条数") @RequestParam Long size) {
        Page<Prod> page = memberCollectionService.queryMemberCollectionProdPageByOpenId(AuthUtils.getLoginMemberOpenId(),current,size);

        return Result.success(null);
    }
}
